package com.andryu.opengl.render

import android.opengl.GLSurfaceView.Renderer
import com.andryu.opengl.jni.LabelSimpleHelper
import com.andryu.base.observer.OpenglJavaObserver
import javax.microedition.khronos.egl.EGLConfig
import javax.microedition.khronos.opengles.GL10

/**
 * 功能简单的渲染器
 */
class LabelSimpleRender : Renderer {

    private var mObserver: OpenglJavaObserver? = null
    private var isCpp: Boolean = false

    constructor(isCpp: Boolean,type:Int ) {
        this.isCpp = isCpp
        initCpp(type)
    }

    constructor(isCpp: Boolean,type: Int, observer: OpenglJavaObserver) : this(isCpp,type) {
        mObserver = observer
        initCpp(type)
    }

    private fun initCpp(type: Int) {
        if (isCpp) {
            LabelSimpleHelper.initRender(type)
        }
    }

    override fun onSurfaceCreated(p0: GL10?, p1: EGLConfig?) {

        if (isCpp) {
            LabelSimpleHelper.onSurfaceCreated()
        } else {
            mObserver?.onSurfaceCreated()
        }
    }

    override fun onSurfaceChanged(p0: GL10?, p1: Int, p2: Int) {
        if (isCpp) {
            LabelSimpleHelper.onSurfaceChanged(p1, p2)
        } else {
            mObserver?.onSurfaceChanged(p1, p2)
        }
    }

    override fun onDrawFrame(p0: GL10?) {
        if (isCpp) {
            LabelSimpleHelper.onDrawFrame()
        } else {
            mObserver?.onDrawFrame()
        }
    }


}